home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume10 / contool / part04 < prev    next >
Encoding:
Internet Message Format  |  1990-10-29  |  21.9 KB

  1. Path: uunet!cs.utexas.edu!sun-barr!newstop!sun!melmac.harris-atd.com
  2. From: chuck@melmac.harris-atd.com (Chuck Musciano)
  3. Newsgroups: comp.sources.x
  4. Subject: v10i037: contool -- replacement for 'cmdtool -C', Part04/06
  5. Message-ID: <144345@sun.Eng.Sun.COM>
  6. Date: 30 Oct 90 06:26:36 GMT
  7. References: <csx-10i034:contool@uunet.UU.NET>
  8. Sender: news@sun.Eng.Sun.COM
  9. Lines: 714
  10. Approved: argv@sun.com
  11.  
  12. Submitted-by: chuck@melmac.harris-atd.com (Chuck Musciano)
  13. news@trantor.harris-atd.com (News stuff)
  14. Posting-number: Volume 10, Issue 37
  15. Archive-name: contool/part04
  16.  
  17. #! /bin/sh
  18. # This is a shell archive.  Remove anything before this line, then unpack
  19. # it by saving it into a file and typing "sh file".  To overwrite existing
  20. # files, type "sh file -c".  You can also feed this as standard input via
  21. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  22. # will see the following message at the end:
  23. #        "End of archive 4 (of 6)."
  24. # Contents:  contool.c
  25. # Wrapped by chuck@melmac on Fri Aug 17 10:00:53 1990
  26. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  27. if test -f 'contool.c' -a "${1}" != "-c" ; then 
  28.   echo shar: Will not clobber existing file \"'contool.c'\"
  29. else
  30. echo shar: Extracting \"'contool.c'\" \(19504 characters\)
  31. sed "s/^X//" >'contool.c' <<'END_OF_FILE'
  32. X/************************************************************************/
  33. X/*    Copyright 1988-1990 by Chuck Musciano and Harris Corporation    */
  34. X/*                                    */
  35. X/*    Permission to use, copy, modify, and distribute this software    */
  36. X/*    and its documentation for any purpose and without fee is    */
  37. X/*    hereby granted, provided that the above copyright notice    */
  38. X/*    appear in all copies and that both that copyright notice and    */
  39. X/*    this permission notice appear in supporting documentation, and    */
  40. X/*    that the name of Chuck Musciano and Harris Corporation not be    */
  41. X/*    used in advertising or publicity pertaining to distribution    */
  42. X/*    of the software without specific, written prior permission.    */
  43. X/*    Chuck Musciano and Harris Corporation make no representations    */
  44. X/*    about the suitability of this software for any purpose.  It is    */
  45. X/*    provided "as is" without express or implied warranty.  This     */
  46. X/*    software may not be sold without the prior explicit permission    */
  47. X/*    of Harris Corporation.                        */
  48. X/************************************************************************/
  49. X
  50. X/************************************************************************/
  51. X/*                                    */
  52. X/*    contool.c    main contool driver                */
  53. X/*                                    */
  54. X/************************************************************************/
  55. X
  56. X#include    <stdio.h>
  57. X#include    <fcntl.h>
  58. X#include    <strings.h>
  59. X#include    <sys/ioctl.h>
  60. X#include    <sys/file.h>
  61. X#include    <sys/types.h>
  62. X#include    <sys/stat.h>
  63. X#include    <sys/param.h>
  64. X
  65. X#include    <X11/Xlib.h>
  66. X
  67. X#include    <xview/xview.h>
  68. X#include    <xview/icon.h>
  69. X#include    <xview/panel.h>
  70. X#include    <xview/textsw.h>
  71. X#include    <xview/xv_xrect.h>
  72. X
  73. X#include    "manifest.h"
  74. X#include    "contool.h"
  75. X#include    "contool_ui.h"
  76. X
  77. X#define        update_value(old, new)        ((old) = ((new) > (old))? (new) : (old))
  78. X
  79. X#define        INPUT_BUFFER_SIZE        4096
  80. X
  81. XEXPORT    Attr_attribute    INSTANCE;
  82. X
  83. XEXPORT    contool_base_objects    *contool_base;
  84. XEXPORT    char            *filter_file;
  85. X
  86. XPUBLIC    Server_image        load_icon();
  87. X
  88. XPRIVATE    short    good_bits[]  = {
  89. X#include    "icons/default_good.icon"
  90. X                   };
  91. XPRIVATE    short    bad_bits[]   = {
  92. X#include    "icons/default_bad.icon"
  93. X                   };
  94. XPRIVATE    short    flash_bits[] = {
  95. X#include    "icons/default_flash.icon"
  96. X                   };
  97. XPRIVATE    short    mask_bits[] = {
  98. X#include    "icons/mask.icon"
  99. X                   };
  100. X
  101. XPRIVATE    char            *ct_usage = "usage: contool [-c <file>] [-l] [-L <file>]\n";
  102. X
  103. XPRIVATE    Server_image        default_good_icon, good = NULL;
  104. XPRIVATE    Server_image        default_bad_icon, bad = NULL;
  105. XPRIVATE    Server_image        default_flash_icon, flash = NULL;
  106. XPRIVATE    Server_image        icon_mask;
  107. X
  108. XPRIVATE    int            bad_is_up;
  109. XPRIVATE    int            beep_count;
  110. XPRIVATE    int            blinking = FALSE;
  111. XPRIVATE    FILE            *command = NULL;
  112. XPRIVATE    Filter            *curr_filter = NULL;
  113. XPRIVATE    int            event_in_progress = FALSE;
  114. XPRIVATE    int            explicit_filters = FALSE;
  115. XPRIVATE    int            masking_works;
  116. XPRIVATE    FILE            *master = NULL;
  117. XPRIVATE    int            old_time = 0;
  118. XPRIVATE    char            *program;
  119. XPRIVATE    FILE            *slave = NULL;
  120. X
  121. XPRIVATE    struct    itimerval    timer = {{0, 500000}, {0, 500000}};
  122. X
  123. X/************************************************************************/
  124. X/*    Manage piping console output to a command             */
  125. X/************************************************************************/
  126. X
  127. X/************************************************************************/
  128. XPRIVATE    start_command(cmd)
  129. X
  130. Xchar    *cmd;
  131. X
  132. X{
  133. X    if (command)
  134. X       pclose(command);
  135. X    if ((command = popen(cmd, "w")) == NULL)
  136. X       internal_error("could not execute \"%s\"", cmd);
  137. X}
  138. X
  139. X/************************************************************************/
  140. XPRIVATE    continue_command(buf)
  141. X
  142. Xchar    *buf;
  143. X
  144. X{
  145. X    if (command)
  146. X       fprintf(command, buf);
  147. X}
  148. X
  149. X/************************************************************************/
  150. XPRIVATE    end_command()
  151. X
  152. X{
  153. X    if (command)
  154. X       pclose(command);
  155. X}
  156. X
  157. X/************************************************************************/
  158. X/*    Some basic console utility routines                 */
  159. X/************************************************************************/
  160. X
  161. X/************************************************************************/
  162. XEXPORT    acquire_console()
  163. X
  164. X{
  165. X    if (ioctl(fileno(slave), TIOCCONS, NULL) == -1)
  166. X       abend("%s: could not attach to /dev/console", program);
  167. X}
  168. X
  169. X/************************************************************************/
  170. XEXPORT    stop_blinking()
  171. X
  172. X{    Icon    icon;
  173. X
  174. X    notify_set_itimer_func(contool_base->base, NULL, ITIMER_REAL, NULL, NULL);
  175. X    icon = (Icon) xv_get(contool_base->base, FRAME_ICON);
  176. X    xv_set(icon, ICON_IMAGE, good, NULL);
  177. X    xv_set(contool_base->base, FRAME_ICON, icon, 0);
  178. X    blinking = FALSE;
  179. X}
  180. X
  181. X/************************************************************************/
  182. XEXPORT    filters_changed()
  183. X
  184. X{
  185. X    curr_filter = NULL;
  186. X    xv_set(contool_base->base, FRAME_LEFT_FOOTER, "", NULL);
  187. X    end_command();
  188. X}
  189. X
  190. X/************************************************************************/
  191. X/*    Various small features                        */
  192. X/************************************************************************/
  193. X
  194. X/************************************************************************/
  195. XEXPORT    Menu_item    print_messages(item, op)
  196. X
  197. XMenu_item    item;
  198. XMenu_generate    op;
  199. X
  200. X{    int    size;
  201. X    char    *buf;
  202. X    FILE    *cmd;
  203. X
  204. X    if (op == MENU_NOTIFY) {
  205. X       if (is_empty(defaults.print_filter))
  206. X          error("You must specify a printer command in the Properties dialog");
  207. X       else if ((cmd = popen(defaults.print_filter, "w")) == NULL)
  208. X          error("Could not execute %s", defaults.print_filter);
  209. X       else {
  210. X          xv_set(contool_base->base, FRAME_BUSY, TRUE, NULL);
  211. X          size = (int) xv_get(contool_base->display, TEXTSW_LENGTH);
  212. X          buf = (char *) malloc(size);
  213. X          xv_get(contool_base->display, TEXTSW_CONTENTS, 0, buf, size);
  214. X          if (fwrite(buf, 1, size, cmd) != size)
  215. X             error("Could not write console contents to printer");
  216. X          pclose(cmd);
  217. X          xv_set(contool_base->base, FRAME_BUSY, FALSE, NULL);
  218. X          }
  219. X       }
  220. X    return item;
  221. X}
  222. X
  223. X/************************************************************************/
  224. XEXPORT    Menu_item    become_console(item, op)
  225. X
  226. XMenu_item    item;
  227. XMenu_generate    op;
  228. X
  229. X{
  230. X    if (op == MENU_NOTIFY)
  231. X       acquire_console();
  232. X    return item;
  233. X}
  234. X
  235. X/************************************************************************/
  236. XEXPORT    Menu_item    clear_messages(item, op)
  237. X
  238. XMenu_item    item;
  239. XMenu_generate    op;
  240. X
  241. X{
  242. X    if (op == MENU_NOTIFY) {
  243. X       textsw_reset(contool_base->display, 0, 0);
  244. X       old_time = 0;
  245. X       }
  246. X    return item;
  247. X}
  248. X
  249. X/************************************************************************/
  250. XEXPORT    Menu_item    reset_filter(item, op)
  251. X
  252. XMenu_item    item;
  253. XMenu_generate    op;
  254. X
  255. X{
  256. X    if (op == MENU_NOTIFY)
  257. X       filters_changed();
  258. X    return item;
  259. X}
  260. X
  261. X/************************************************************************/
  262. XPRIVATE    change_icon(image, use_mask)
  263. X
  264. XServer_image    image;
  265. Xint        use_mask;
  266. X
  267. X{    Icon    icon;
  268. X
  269. X    icon = (Icon) xv_get(contool_base->base, FRAME_ICON);
  270. X    xv_set(icon,
  271. X          ICON_IMAGE, image,
  272. X          XV_WIDTH, (int) xv_get(image, XV_WIDTH),
  273. X          XV_HEIGHT, (int) xv_get(image, XV_HEIGHT),
  274. X           NULL);
  275. X    if (masking_works && use_mask)
  276. X       xv_set(icon, ICON_MASK_IMAGE, icon_mask, NULL);
  277. X    xv_set(contool_base->base, FRAME_ICON, icon, NULL);
  278. X}
  279. X
  280. X/************************************************************************/
  281. XEXPORT    update_icons()
  282. X
  283. X{    char    msg[1024];
  284. X
  285. X    if (good && good != default_good_icon)
  286. X       xv_destroy(good);
  287. X    if (bad && bad != default_bad_icon)
  288. X       xv_destroy(bad);
  289. X    if (flash && flash != default_flash_icon)
  290. X       xv_destroy(flash);
  291. X
  292. X    good  = (defaults.good_icon  == NULL)? default_good_icon  : load_icon(defaults.good_icon, msg);
  293. X    bad   = (defaults.bad_icon   == NULL)? default_bad_icon   : load_icon(defaults.bad_icon, msg);
  294. X    flash = (defaults.flash_icon == NULL)? default_flash_icon : load_icon(defaults.flash_icon, msg);
  295. X
  296. X    if (!blinking)
  297. X       change_icon(good, good == default_good_icon);
  298. X}
  299. X
  300. X/************************************************************************/
  301. X/*    Now, filter  handlers                        */
  302. X/************************************************************************/
  303. X
  304. X/************************************************************************/
  305. XPRIVATE    internal_message(a, b, c, d, e, f)
  306. X
  307. Xint    a, b, c, d, e, f;
  308. X
  309. X{    char    buf[1024];
  310. X
  311. X    sprintf(buf, a, b, c, d, e, f);
  312. X    time_stamp();
  313. X    write_log(buf);
  314. X    do_insertion(buf, strlen(buf));
  315. X}
  316. X
  317. X/************************************************************************/
  318. XPRIVATE    internal_error(a, b, c, d, e, f)
  319. X
  320. Xint    a, b, c, d, e, f;
  321. X
  322. X{    char    buf[1024];
  323. X
  324. X    sprintf(buf, a, b, c, d, e, f);
  325. X    time_stamp();
  326. X    fprintf(stderr, "*** %s: %s\n", program, buf);
  327. X}
  328. X
  329. X/************************************************************************/
  330. XPRIVATE    load_filters()
  331. X
  332. X{    struct    stat    sb;
  333. X    static    int    load_time = 0;
  334. X
  335. X    if (access(filter_file, R_OK) == -1) {
  336. X       if (explicit_filters && load_time == 0) {
  337. X          internal_error("filter file %s cannot be accessed", filter_file);
  338. X          load_time = 1;
  339. X          }
  340. X       }
  341. X    else if (stat(filter_file, &sb) == 0 && sb.st_mtime > load_time)
  342. X       if (lex_init(filter_file)) {
  343. X          yyparse();
  344. X          if (!parse_errors_occured) {
  345. X             free_list(filters);
  346. X             free(parsed_defaults);
  347. X             filters = parsed_filters;
  348. X             internal_message("*** filters loaded from %s\n", filter_file);
  349. X             load_time = sb.st_mtime;
  350. X             }
  351. X          }
  352. X       else {
  353. X          internal_error("error accessing configuration file %s", filter_file);
  354. X          load_time = 1;
  355. X          }
  356. X}
  357. X
  358. X/************************************************************************/
  359. X/*    Various event handlers for the console frame            */
  360. X/************************************************************************/
  361. X
  362. X/************************************************************************/
  363. XPRIVATE    Notify_value    blink_proc(me, which)
  364. X
  365. Xint    *me;
  366. Xint    which;
  367. X
  368. X{
  369. X    if (event_in_progress)
  370. X       return(NOTIFY_DONE);
  371. X    if (beep_count > 0) {
  372. X       window_bell(contool_base->base);
  373. X       beep_count--;
  374. X       }
  375. X    if (blinking) {
  376. X       if (bad_is_up)
  377. X          change_icon(flash, flash == default_flash_icon);
  378. X       else
  379. X          change_icon(bad, bad == default_bad_icon);
  380. X       bad_is_up = !bad_is_up;
  381. X       }
  382. X    if (beep_count == 0 && !blinking)
  383. X       notify_set_itimer_func(contool_base->base, blink_proc, ITIMER_REAL, NULL, NULL);
  384. X    return(NOTIFY_DONE);
  385. X}
  386. X
  387. X/************************************************************************/
  388. XPRIVATE    Notify_value    close_proc(frame, event, arg, type)
  389. X
  390. XFrame    frame;
  391. XEvent    *event;
  392. XNotify_arg    arg;
  393. XNotify_event_type    type;
  394. X
  395. X{
  396. X    event_in_progress = TRUE;
  397. X    if (event_action(event) == ACTION_OPEN && blinking) {
  398. X       notify_set_itimer_func(contool_base->base, blink_proc, ITIMER_REAL, NULL, NULL);
  399. X       change_icon(good, good = default_good_icon);
  400. X       blinking = FALSE;
  401. X       }
  402. X    event_in_progress = FALSE;
  403. X    return(notify_next_event_func(frame, event, arg, type));
  404. X}
  405. X
  406. X/************************************************************************/
  407. XPRIVATE    Notify_value    destroy_proc(frame, status)
  408. X
  409. XFrame    frame;
  410. XDestroy_status    status;
  411. X
  412. X{
  413. X    if (status == DESTROY_CHECKING) {
  414. X       textsw_reset(contool_base->display, 0, 0);
  415. X       return(NOTIFY_DONE);
  416. X       }
  417. X    else
  418. X       return(notify_next_destroy_func(frame, status));
  419. X}
  420. X
  421. X/************************************************************************/
  422. X/*    Routines which handle capturing and displaying messages        */
  423. X/************************************************************************/
  424. X
  425. X/************************************************************************/
  426. XPRIVATE    do_insertion(buf, len)
  427. X
  428. Xchar    *buf;
  429. Xint    len;
  430. X
  431. X{    int    first, last, sw_len;
  432. X    char    *temp;
  433. X
  434. X    while ((int) xv_get(contool_base->display, TEXTSW_LENGTH) + len > defaults.max_size) {
  435. X       first = 1;
  436. X       last = TEXTSW_INFINITY;
  437. X       if (textsw_find_bytes(contool_base->display, &first, &last, "\n<<<", 4, 0) == -1)
  438. X          if (textsw_find_bytes(contool_base->display, &first, &last, "\n", 1, 0) == -1)
  439. X             first = defaults.delete_amount;
  440. X       textsw_erase(contool_base->display, 0, first + 1);
  441. X       sw_len = (int) xv_get(contool_base->display, TEXTSW_LENGTH);
  442. X       temp = (char *) malloc((unsigned) sw_len);
  443. X       xv_get(contool_base->display, TEXTSW_CONTENTS, 0, temp, sw_len);
  444. X       textsw_reset(contool_base->display, 0, 0);
  445. X       textsw_insert(contool_base->display, temp, sw_len);
  446. X       free(temp);
  447. X       }
  448. X    xv_set(contool_base->display, TEXTSW_INSERTION_POINT, TEXTSW_INFINITY, 0);
  449. X    textsw_insert(contool_base->display, buf, len);
  450. X}
  451. X
  452. X/************************************************************************/
  453. XPRIVATE    time_stamp()
  454. X
  455. X{    int    t, pos;
  456. X    char    buf[5];
  457. X
  458. X       t = time(0);
  459. X       if (t - old_time >= defaults.stamp_resolution) {
  460. X          xv_set(contool_base->display, TEXTSW_INSERTION_POINT, TEXTSW_INFINITY, 0);
  461. X          pos = (int) xv_get(contool_base->display, TEXTSW_LENGTH);
  462. X          if (pos != 0) {
  463. X             xv_get(contool_base->display, TEXTSW_CONTENTS, pos - 1, buf, 1);
  464. X             if (buf[0] != '\n')
  465. X                do_insertion("\n", 1);
  466. X             }
  467. X          do_insertion("\n<<< ", 5);
  468. X          do_insertion(ctime(&t), 24);
  469. X          do_insertion(" >>>\n", 5);
  470. X          old_time = t;
  471. X          }
  472. X}
  473. X
  474. X/************************************************************************/
  475. XPRIVATE    Notify_value    input_func(me, fd)
  476. X
  477. Xint    *me;
  478. Xint    fd;
  479. X
  480. X{    char    old_c, *s, *t, buf[1024];
  481. X    Filter    *f;
  482. X    int    count, do_blink = FALSE, do_open = FALSE;
  483. X    static    char    in_buf[INPUT_BUFFER_SIZE + 2];
  484. X
  485. X    while ((count = read(fileno(master), in_buf, INPUT_BUFFER_SIZE)) >= 0) {
  486. X       in_buf[count] = '\0';
  487. X       while (s = index(in_buf, '\015')) {
  488. X          strcpy(s, s + 1);
  489. X          count--;
  490. X          }
  491. X       for (t = in_buf; *t; *s = old_c, t = s) {
  492. X          if (s = index(t, '\n')) {
  493. X             old_c = *++s;
  494. X             *s = '\0';
  495. X             }
  496. X          else {
  497. X             s = t + strlen(t);
  498. X             old_c = '\0';
  499. X             }
  500. X          if (!defaults.log_after)
  501. X             write_log(t);
  502. X          if (curr_filter == NULL) {
  503. X             load_filters();
  504. X             for (f = filters; f; f = f->next)
  505. X                if (f->start_re && match_exp(f->start_re, f->start_circf, t)) {
  506. X                   if (f->save) {
  507. X                      update_value(do_blink, f->flash);
  508. X                      update_value(beep_count, f->beep);
  509. X                      update_value(do_open, f->open);
  510. X                      if (f->stamp)
  511. X                         time_stamp();
  512. X                      do_insertion(t, strlen(t));
  513. X                      if (f->command) {
  514. X                         start_command(f->command);
  515. X                         continue_command(t);
  516. X                         if (f->stop == NULL)
  517. X                            end_command();
  518. X                         }
  519. X                      if (defaults.log_after)
  520. X                 write_log(t);
  521. X                      }
  522. X                   if (f->stop) {
  523. X                      curr_filter = f;
  524. X                      sprintf(buf, "Filtering \"%s\"...", f->start);
  525. X                      xv_set(contool_base->base, FRAME_LEFT_FOOTER, buf, NULL);
  526. X                      }
  527. X                   break;
  528. X                   }
  529. X             if (f == NULL) {
  530. X                if (defaults.stamp)
  531. X                   time_stamp();
  532. X                if (defaults.command) {
  533. X                   start_command(defaults.command);
  534. X                   continue_command(t);
  535. X                   end_command();
  536. X                   }
  537. X            if (defaults.log_after)
  538. X                   write_log(t);
  539. X                do_insertion(t, strlen(t));
  540. X                update_value(do_blink, defaults.flash);
  541. X                update_value(do_open, defaults.open);
  542. X                update_value(beep_count, defaults.beep);
  543. X                }
  544. X             }
  545. X          else {
  546. X             if (curr_filter->save) {
  547. X                if (curr_filter->stamp)
  548. X                   time_stamp();
  549. X            if (defaults.log_after)
  550. X                   write_log(t);
  551. X            do_insertion(t, strlen(t));
  552. X            if (curr_filter->command)
  553. X               continue_command(t);
  554. X                }
  555. X             if (match_exp(curr_filter->stop_re, curr_filter->stop_circf, t)) {
  556. X                xv_set(contool_base->base, FRAME_LEFT_FOOTER, "", NULL);
  557. X                if (curr_filter->command)
  558. X                   end_command();
  559. X                curr_filter = NULL;
  560. X                }
  561. X             }
  562. X          }
  563. X       }
  564. X    xv_set(contool_base->display, TEXTSW_UPDATE_SCROLLBAR, 0);
  565. X    if (do_open)
  566. X       xv_set(contool_base->base, FRAME_CLOSED, FALSE, 0);
  567. X    if (do_blink)
  568. X       if (xv_get(contool_base->base, FRAME_CLOSED) && !blinking) {
  569. X          change_icon(bad, bad == default_bad_icon);
  570. X          xv_set(contool_base->base, WIN_SHOW, TRUE, 0);
  571. X          blinking = TRUE;
  572. X          bad_is_up = TRUE;
  573. X          notify_set_itimer_func(contool_base->base, blink_proc, ITIMER_REAL, &timer, NULL);
  574. X          }
  575. X    if (beep_count > 0 || blinking)
  576. X       notify_set_itimer_func(contool_base->base, blink_proc, ITIMER_REAL, &timer, NULL);
  577. X    return(NOTIFY_DONE);
  578. X}
  579. X
  580. X/************************************************************************/
  581. X/*    Routines which parse options, create windows, and main()    */
  582. X/************************************************************************/
  583. X
  584. X/************************************************************************/
  585. XPRIVATE    parse_options(argc, argv)
  586. X
  587. Xint    *argc;
  588. Xchar    **argv;
  589. X
  590. X{    char    *s, c, path[1024], *log_file = NULL;
  591. X    int    log = FALSE;
  592. X
  593. X    sprintf(path, "%s/.contool", getenv("HOME"));
  594. X    filter_file = strsave(path);
  595. X
  596. X    while ((c = getopt(argc, argv, "c:lL:?", &s)) != EOF)
  597. X       switch (c) {
  598. X          case 'c' : filter_file = expand_tilde(s);
  599. X                   explicit_filters = TRUE;
  600. X                   break;
  601. X          case 'l' : log = TRUE;
  602. X                   break;
  603. X          case 'L' : log_file = expand_tilde(s);
  604. X                   break;
  605. X          case '?' : fprintf(stderr, ct_usage);
  606. X                   exit(0);
  607. X                   break;
  608. X          default  : fprintf(stderr, ct_usage);
  609. X                     exit(1);
  610. X          }
  611. X
  612. X    if (lex_init(filter_file)) {
  613. X       yyparse();
  614. X       if (parsed_defaults)
  615. X          defaults = *parsed_defaults;
  616. X       if (log_file)
  617. X          defaults.log_file = log_file;
  618. X       if (log)
  619. X          enable_logging();
  620. X       }
  621. X    else if (explicit_filters)
  622. X       error("Could not read configuration file %s", filter_file);
  623. X}
  624. X
  625. X/************************************************************************/
  626. Xmain(argc, argv)
  627. X
  628. Xint    argc;
  629. Xchar    **argv;
  630. X
  631. X{    char    buf[1024], *path, *open_psuedo_tty();
  632. X    int    i;
  633. X    XWindowAttributes    attr;
  634. X
  635. X    program = strsave(argv[0]);
  636. X
  637. X    path = open_psuedo_tty(&master, "r", &slave, "w");
  638. X    if (master == NULL)
  639. X       abend("%s: couldn't open any psuedo-tty", program);
  640. X    if (slave == NULL)
  641. X       abend("%s: couldn't open slave side of %s", program, path);
  642. X
  643. X    i = fcntl(fileno(master), F_GETFL, 0);
  644. X    i |= FNDELAY;
  645. X    if (fcntl(fileno(master), F_SETFL, i) == -1)
  646. X       abend("%s: could not force %s to non-blocking i/o", program);
  647. X
  648. X    acquire_console(path);
  649. X
  650. X    xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, 0);
  651. X    INSTANCE = xv_unique_key();
  652. X
  653. X    contool_base = contool_base_objects_initialize(NULL, NULL);
  654. X    default_good_icon  = (Server_image) xv_create(NULL, SERVER_IMAGE,
  655. X                             XV_WIDTH, 64,
  656. X                             XV_HEIGHT, 64,
  657. X                             SERVER_IMAGE_BITS, good_bits,
  658. X                              NULL);
  659. X    default_bad_icon   = (Server_image) xv_create(NULL, SERVER_IMAGE,
  660. X                             XV_WIDTH, 64,
  661. X                             XV_HEIGHT, 64,
  662. X                             SERVER_IMAGE_BITS, bad_bits,
  663. X                              NULL);
  664. X    default_flash_icon = (Server_image) xv_create(NULL, SERVER_IMAGE,
  665. X                             XV_WIDTH, 64,
  666. X                             XV_HEIGHT, 64,
  667. X                             SERVER_IMAGE_BITS, flash_bits,
  668. X                              NULL);
  669. X    icon_mask          = (Server_image) xv_create(NULL, SERVER_IMAGE,
  670. X                             XV_WIDTH, 64,
  671. X                             XV_HEIGHT, 64,
  672. X                             SERVER_IMAGE_BITS, mask_bits,
  673. X                              NULL);
  674. X    disable_logging(contool_base);
  675. X
  676. X    XGetWindowAttributes(xv_get(contool_base->base, XV_DISPLAY), xv_get(xv_get(contool_base->base, XV_ROOT), XV_XID), &attr);
  677. X    masking_works = (attr.depth > 1);
  678. X
  679. X    parse_options(&argc, argv);
  680. X    load_filters();
  681. X    update_icons();
  682. X
  683. X    notify_set_input_func(contool_base->base, input_func, fileno(master));
  684. X    notify_interpose_destroy_func(contool_base->base, destroy_proc);
  685. X    notify_interpose_event_func(contool_base->base, close_proc, NOTIFY_SAFE);
  686. X
  687. X    xv_main_loop(contool_base->base);
  688. X    exit(0);
  689. X}
  690. END_OF_FILE
  691. if test 19504 -ne `wc -c <'contool.c'`; then
  692.     echo shar: \"'contool.c'\" unpacked with wrong size!
  693. fi
  694. # end of 'contool.c'
  695. fi
  696. echo shar: End of archive 4 \(of 6\).
  697. cp /dev/null ark4isdone
  698. MISSING=""
  699. for I in 1 2 3 4 5 6 ; do
  700.     if test ! -f ark${I}isdone ; then
  701.     MISSING="${MISSING} ${I}"
  702.     fi
  703. done
  704. if test "${MISSING}" = "" ; then
  705.     echo You have unpacked all 6 archives.
  706.     rm -f ark[1-9]isdone
  707. else
  708.     echo You still need to unpack the following archives:
  709.     echo "        " ${MISSING}
  710. fi
  711. ##  End of shell archive.
  712. exit 0
  713.  
  714. Chuck Musciano                ARPA  : chuck@trantor.harris-atd.com
  715. Harris Corporation             Usenet: ...!uunet!x102a!trantor!chuck
  716. PO Box 37, MS 3A/1912            AT&T  : (407) 727-6131
  717. Melbourne, FL 32902            FAX   : (407) 729-2537
  718.  
  719. A good newspaper is never good enough,
  720.     but a lousy newspaper is a joy forever.        -- Garrison Keillor
  721.  
  722. dan
  723. ----------------------------------------------------
  724. O'Reilly && Associates   argv@sun.com / argv@ora.com
  725. Opinions expressed reflect those of the author only.
  726.